package org.greatstorm.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.greatstorm.dao.ArticleDao;
import org.greatstorm.dao.GeneralDao;
import org.greatstorm.entity.Article;
import org.greatstorm.entity.EntityObject;
import org.greatstorm.util.Filter;
import org.greatstorm.util.Operator;
import org.greatstorm.util.Sort;
import org.greatstorm.util.SortDirection;

import com.google.inject.Singleton;

@Singleton
public class ArticleDaoImpl extends GeneralDao implements ArticleDao {

	@Override
	protected String getEntityName() {
		return Article.KIND;
	}

	@Override
	public List<EntityObject> getArticleByCategory(int pageNo, int pagesize,
			String key) {
		Filter f = new Filter();
		f.setKey(Article.CATEGORY_FK);
		f.setOpt(Operator.OPT_EQUAL);
		f.setValue(key);

		Sort s = new Sort();
		s.setSortKey(Article.CREATE_DATE);
		s.setSortDirection(SortDirection.DESC);

		List<Filter> filterList = new ArrayList<Filter>();
		filterList.add(f);

		return this.getEntityListByFilter(pageNo, pagesize, filterList, s);
	}

	@Override
	public List<EntityObject> getAllArticle(Integer pageno, int pagesize) {
		return this.getAll(pageno, pagesize);
	}
}
